<?php


namespace app\api\controller\manystore;

use app\common\model\Banji;

class Monitor extends Base
{
    //如果$noNeedLogin为空表示所有接口都需要登录才能请求
    //如果$noNeedRight为空表示所有接口都需要验证权限才能请求
    //如果接口已经设置无需登录,那也就无需鉴权了
    //
    // 无需登录的接口,*表示全部
    protected $noNeedLogin = ['*'];
    // 无需鉴权的接口,*表示全部
    protected $noNeedRight = ['*'];

    public function _initialize()
    {
        parent::_initialize();

        //判断到期时间
        // if($this->student->endtime <= time()) {
        //   \app\common\model\manystore\Student::update(['is_see' => 0],['id' => $this->student->id]);
        // }
    }

    //监控信息
    public function list()
    {
        $page = $this->request->get('page');
        $limit = $this->request->get('limit',LIMIT);

//        $where['status'] = 1;
        $user = $this->auth->getUserinfo();

        if($user['is_teacher'] == 0) {
            if($this->student->is_see == 0) {
                $result = array("total" => 0, "rows" => []);
                $this->success('返回成功',$result);
            }
        }

        $where['id'] = ['in',$this->banji->monitor_info_ids];

        $model = new \app\common\model\manystore\MonitorInfo();
        $list = $model->where($where)->paginate($limit,false,['page' => $page]);

        $result = array("total" => $list->total(), "rows" => $list->items());
        $this->success('返回成功',$result);
    }

    //监控详情
    public function detail()
    {
        $id = $this->request->get('id');

        $model = new \app\common\model\manystore\MonitorInfo();
        $info = $model->where(['id' => $id])->find();

        $this->success('返回成功', $info);
    }
}